package com.huidu.bitrade.controller;

import com.huidu.bitrade.dto.AcAwardExportDto;
import com.huidu.bitrade.result.page.AwardExportQuery;
import com.huidu.bitrade.result.page.PageCondition;
import com.huidu.bitrade.service.MemberAwardService;
import com.huidu.bitrade.util.FileUtil;
import com.huidu.bitrade.util.MessageResult;
import com.huidu.bitrade.vo.AcReferrerRewardsVO;
import com.huidu.bitrade.vo.export.*;
import com.huidu.bitrade.vo.export.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("export")
@Api(tags = "用户奖励导出")
public class MemberAwardExportController {

    private final MemberAwardService memberAwardService;

    @ApiOperation("升星奖励导出")
    @PostMapping("/memberStarRecordExport")
    public MessageResult memberStarRecordExport(@RequestParam(required = false) String startTime,String endTime, HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<AcReferrerRewardsExport> list = memberAwardService.memberStarRecordExport(AcAwardExportDto.builder()
                .startTime(startTime).endTime(endTime).build(), PageCondition.page(new AwardExportQuery()),new ArrayList<>());
        if(CollectionUtils.isEmpty(list)){
            return MessageResult.error("导出数据为空");
        }
        return new FileUtil().exportExcel(request, response, list, "memberStarRecord");
    }

    @ApiOperation("HDC奖励导出")
    @PostMapping("/hdcAwardExport")
    public MessageResult hdcAwardExport(@RequestParam(required = false) String startTime,String endTime, HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<AcHdcAwardExport> list = memberAwardService.hdcAwardExport(AcAwardExportDto.builder()
                .startTime(startTime).endTime(endTime).build(),PageCondition.page(new AwardExportQuery()),new ArrayList<>());
        if(CollectionUtils.isEmpty(list)){
            return MessageResult.error("导出数据为空");
        }
        return new FileUtil().exportExcel(request, response, list, "hdcAward");
    }

    @ApiOperation("购买记录导出")
    @PostMapping("/memberRecordExport")
    public MessageResult memberRecordExport(@RequestParam(required = false) String startTime,String endTime, HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<AcMemberExport> list = memberAwardService.memberRecordExport(AcAwardExportDto.builder()
                .startTime(startTime).endTime(endTime).build(),PageCondition.page(new AwardExportQuery()),new ArrayList<>());
        if(CollectionUtils.isEmpty(list)){
            return MessageResult.error("导出数据为空");
        }
        return new FileUtil().exportExcel(request, response, list, "memberRecord");
    }

    @ApiOperation("信息查询导出")
    @PostMapping("/memberInfoExport")
    public MessageResult memberInfoExport(@RequestParam(required = false) String startTime,String endTime, HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<AcReferrerRewardsVO> list = memberAwardService.memberInfoExport(AcAwardExportDto.builder()
                .startTime(startTime).endTime(endTime).build(),PageCondition.page(new AwardExportQuery()),new ArrayList<>());
        if(CollectionUtils.isEmpty(list)){
            return MessageResult.error("导出数据为空");
        }
        return new FileUtil().exportExcel(request, response, list, "memberInfo");
    }

    @ApiOperation("交易手续费奖励导出")
    @PostMapping("/chargeAwardRecordExport")
    public MessageResult chargeAwardRecordExport(@RequestParam(required = false) String startTime,String endTime, HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<AcChargeHdcAwardExport> list = memberAwardService.chargeAwardRecordExport(AcAwardExportDto.builder()
                .startTime(startTime).endTime(endTime).build(),PageCondition.page(new AwardExportQuery()),new ArrayList<>());
        if(CollectionUtils.isEmpty(list)){
            return MessageResult.error("导出数据为空");
        }
        return new FileUtil().exportExcel(request, response, list, "chargeAwardRecord");
    }

    @ApiOperation("团队手续费奖励导出")
    @PostMapping("/groupChargeAwardExport")
    public MessageResult groupChargeAwardExport(@RequestParam(required = false) String startTime,String endTime, HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<AcGroupChargeAwardExport> list = memberAwardService.groupChargeAwardExport(AcAwardExportDto.builder()
                .startTime(startTime).endTime(endTime).build(),PageCondition.page(new AwardExportQuery()),new ArrayList<>());
        if(CollectionUtils.isEmpty(list)){
            return MessageResult.error("导出数据为空");
        }
        return new FileUtil().exportExcel(request, response, list, "groupChargeAward");
    }


}
